import modelEntity from "./modelEntity";
import RoleTemplate from "./RoleTemplate";
export default class UserRole extends modelEntity {
  constructor(options) {
    super(options);
    this.Ref_User_Guid = options.Ref_User_Guid;
    this.Ref_RoleTemplate_Guid = options.Ref_RoleTemplate_Guid;
    this.Param = options.Param;
    this.roleTemplate = null;
    if (options.roleTemplate) {
      this.roleTemplate = new RoleTemplate(options.roleTemplate);
    }
  }
  static newInstance() {
    return new UserRole({
      Ref_User_Guid: null,
      Ref_RoleTemplate_Guid: null,
      Param: null,
    })
  }
  static loadList() {
    return new Promise((resolve, reject) => {
      getApp().globalData.api.http_get(`${getApp().globalData.baseUrl}/api/sys/userrole`)
        .then(
          res => {
            console.log(res);
            let list = [];
            res.forEach(x => {
              list.push(new UserRole(x));
            });
            resolve(list);
          }
        )
    })
  }
  create() {
    return new Promise((resolve, reject) => {
      window.api.http_post("/api/sys/userrole", this)
        .then(
          res => {
            let model = new UserRole(res);
            resolve(model);
          }
        )
    })
  }
  delete() {
    return new Promise((resolve, reject) => {
      window.api.http_delete("/api/sys/userrole", this)
        .then(
          res => {
            resolve(res);
          }
        )
    })
  }
  modify() {
    return new Promise((resolve, reject) => {
      window.api.http_put("/api/sys/userrole", this)
        .then(
          res => {
            let model = new UserRole(res);
            resolve(model);
          }
        )
    })
  }
}
